import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { ResourcesForm, ResourcesPage, ResourcesQuery } from "./types";

/**
 * 获取分页列表
 *
 * @param queryParams
 */
export function getResourcesPage(
  queryParams: ResourcesQuery
): AxiosPromise<PageResult<ResourcesPage[]>> {
  return request({
    url: "/admin/resources/index",
    method: "get",
    params: queryParams,
  });
}

export function getDashboard(): AxiosPromise<ResourcesPage[]> {
  return request({
    url: "/admin/resources/dashboard",
    method: "get",
  });
}

/**
 * 获取表单详情
 * @param ids
 */
export function getResourcesForm(ids: number): AxiosPromise<ResourcesForm> {
  return request({
    url: "/admin/resources/edit",
    method: "get",
    params: {
      ids: ids,
    },
  });
}

/**
 * 添加
 * @param data
 */
export function addResources(data: any) {
  return request({
    url: "/admin/resources/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改
 * @param id
 * @param data
 */
export function updateResources(data: ResourcesForm) {
  return request({
    url: "/admin/resources/edit",
    method: "put",
    data: data,
  });
}

/**
 * 删除
 * @param data
 */
export function deleteResources(data: any) {
  return request({
    url: "/admin/resources/del",
    method: "delete",
    data,
  });
}
